﻿@model  Model.PageRole
@{
    ViewBag.Title = "作业任务日志管理";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <style type="text/css">
        .pagTable
        {
            width: 100%;
            border-left: solid 1px #ccc;
            table-layout: fixed;
        }
        #ClearLogDialog
        {
            width: 500px;
            height: 150px;
            display: none;
            line-height: 20px;
            position: absolute;
            top: 84px;
            left: 200px;
            z-index: 1002;
            word-wrap: break-word;
            word-break: normal;
            background-color: #ffffff;
        }
        .pagTable td
        {
            height: 25px;
            border-right: 1px solid #ccc;
            border-bottom: 1px solid #ccc;
            padding-right: 3px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
    <script src="/Res/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script type="text/javascript">
        var doActionOptions = "<select onchange='return DoAction(this.options.selectedIndex,this.value)' style='width: 96%; '>"
        + "<option value=''>-请选择-</option>";

        var opts = {
            rows: 15,
            height: 450,
            url: "",
            para: {},
            idField: "GUID",
            checkbox: false,
            columns: [
                     { field: 'TaskName', title: '任务名称', width: 15 },
                     { field: 'StepName', title: '步骤名称', width: 20 },
                     { field: 'StartTimeStr', title: '开始时间', width: 12, align: 'center' },
                     { field: 'EndTimeStr', title: '结束时间', width: 12, align: 'center' },
                     { field: 'RunDuration', title: '持续时间', width: 8, align: 'center',
                         formatter: function (value, rowData, rowIndex) {
                             return value + "秒";
                         }
                     },
                     { field: 'BatchTimeStr', title: '执行时间', width: 12, align: 'center' },
                     { field: 'TaskStatus', title: '任务状态', width: 8, align: 'center',
                         formatter: function (value, rowData, rowIndex) {
                             switch (value) {
                                 case 1:
                                     return "任务启动";
                                     break;
                                 case 2:
                                     return "任务成功";
                                     break;
                                 case 3:
                                     return "任务失败";
                                     break;
                             }
                             return "&nbsp;";
                         }
                     },
                     { field: 'GUID', title: '操作', width: 5, align: 'center',
                         formatter: function (value, rowData, rowIndex) {
                             return "<a onclick='ReadEtlLog(\"" + value + "\");' class='grid_a'>查看</a>";
                         }
                     }
                    ]

        };

        $(function () {
            InitList();
        });

        function btnSearch_Click() {
            thisPageNum = 1;
            InitList();
        }
        function btnClear_Click() {

            $(".sel_TimeFrom").datebox('setValue', "");
            $(".sel_TimeTo").datebox('setValue', "");

            $('#sel_TaskName').val("");
            $('#sel_TaskStatus').val("");
            $('#sel_TimeFrom').val("");
            $('#sel_TimeTo').val("");

            $('.txt_SourceSysName').val("");
            $('#sel_SourceSysGuid').val("");

            $('.txt_ModelName').val("");
            $('#sel_ModelGuid').val("");

            $('.txt_TargetSysName').val("");
            $('#sel_TargetSysGuid').val("");
        }
        function btnSelect_Click(type) {
            if (type == "S") {
                selectSourceList();
            }
            else if (type == "M") {
                selectModelList();
            }
            else if (type == "T") {
                selectTargetList();
            }
        }

        function selectSourceList() {
            showModalMany('SelectSourceList', '/SystemConfiguration/SelectSourceList?selectCount=1&dbName=' + encodeURI($.getUrlParam("dbName")), '810', '460',
                function (v) {
                    if (typeof (v) == "undefined") return;
                    if (v.length > 0) {
                        $('.txt_SourceSysName').val(v[0].SourceSysName);
                        $('#sel_SourceSysGuid').val(v[0].GUID);
                    }
                });
        }

        function selectModelList() {
            showModalMany('SelectModelList', '/ModelConfig/ModelList?dbName=' + encodeURI($.getUrlParam("dbName")), '900', '480',
            function (v) {
                if (typeof (v) == "undefined") return;
                if (v.length > 1) {
                    alert("请选择一个模型");
                }
                else if (v.length > 0) {
                    var re = /;'>(.*?)<\/a>/;
                    var value = re.exec(v[0].TableName)[1];
                    $('.txt_ModelName').val(value);
                    $('#sel_ModelGuid').val(v[0].GUID);
                }
            });
        }

        function selectTargetList() {
            showModalMany('SelectTargetList', '/EtlTarget/SelectTargetList?selectCount=1&dbName=' + encodeURI($.getUrlParam("dbName")), '810', '460',
                function (v) {
                    if (typeof (v) == "undefined") return;
                    if (v.length > 0) {
                        $('.txt_TargetSysName').val(v[0].TargetSysName);
                        $('#sel_TargetSysGuid').val(v[0].GUID);
                    }
                });
        }

        function InitList(postUrl) {
            if (typeof (postUrl) == "undefined" || postUrl.length == 0) {
                postUrl = "/SysLog/SysEtlLogList?dbName=" + encodeURI($.getUrlParam("dbName"));
            }
            $('#sel_TimeFrom').val($(".sel_TimeFrom").datebox('getValue'));
            $('#sel_TimeTo').val($(".sel_TimeTo").datebox('getValue'));

            opts.para = { query: jv.GetDivJson($("#tableSearchDQPanel"), 4) };
            opts.url = postUrl;
            $("#DataGrid").dg(opts);
        }
        function btnSearch_Clear() {
            $(".txt_SourceSysName").val("");
            $(".txt_ModelName").val("");
            $(".txt_TargetSysName").val("");
            $(".sel_TimeFrom").datebox('setValue', "");
            $(".sel_TimeTo").datebox('setValue', "");
            jv.SetDivEmpty($("#tableSearchDQPanel"), 4);
        }
        function ReadEtlLog(id) {
            var url = "/SysLog/ReadEtlLog?id=" + id + "&dbName=" + encodeURI($.getUrlParam("dbName"));
            showModalMany('TaskStatus', url, '600', '365',
                            function (result) {
                            });
        }

        function ClearLogDialog() {
            $('#ClearLogDialog').show();
            $('#DIVMask').show();
        }
        function ClearLog(id) {
            var a = $(".delDate").datebox('getValue');
            if (a == "") {
                alert("请选择删除日期。");
                return;
            }
            var arr = a.split("-");
            var starttime = new Date(arr[0], arr[1], parseInt(arr[2]) + 1);
            var starttimes = starttime.getTime();

            var b = new Date();
            var btimes = new Date(b.getFullYear(), b.getMonth() + 1, b.getDate());
            if (starttimes > btimes.getTime()) {
                alert("删除日期应该小于当前日期。");
                return;
            }
            if (confirm("确定要清空DQ日志吗？")) {
                $.post("/SysLog/ClearETLLog/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&date=" + a, function (res) {
                    if (res == "1") {
                        alert("操作成功！");
                        $('#ClearLogDialog').hide();
                        $('#DIVMask').hide();
                        thisPageNum = 1;
                        InitList();
                    }
                    else if (res == "0")
                        alert("删除失败！");
                    else
                        alert("删除失败！" + res);
                });
            }
        }
    </script>
}
<div style="margin: 5px;">
    @{
        // 渲染输出列表
        var dataSearch = new ViewDataDictionary();
        dataSearch.Add("PanelTitle", "作业日志搜索");
        @Html.Partial("_SearchTitlePanel", dataSearch);
        //Html.RenderPartial("_SearchTitlePanel", dataSearch);
    }
    @Html.Partial("_SearchEtlPanel")
</div>
<div style="margin: 5px; min-height: 300px;">
    @{
        // 渲染输出列表
        var dataGrid = new ViewDataDictionary();
        dataGrid.Add("PanelTitle", "作业日志列表");
        dataGrid.Add("GridID", "DataGrid");
        dataGrid.Add("ShowAddButton", false);
        dataGrid.Add("ShowDeleteButton", false);
        if (Model.role == 2)
        {
            dataGrid.Add("ShowOtherButton", true);
            dataGrid.Add("OtherButtonValue", "清除日志");
            dataGrid.Add("OtherButtonClick", "ClearLogDialog()");
        }
        dataGrid.Add("ShowBackButton", false);
        dataGrid.Add("ShowCloseButton", false);
        dataGrid.Add("ShowPager", true);
        dataGrid.Add("ShowLoading", true);
        @Html.Partial("_GridPanel", dataGrid);
    }
</div>
<div id="ClearLogDialog" class="ClearLogDialog">
    <table class="listTitle">
        <tbody>
            <tr>
                <td width="15">
                    <img src="/images/search.png">
                </td>
                <td width="260">
                    清除日志
                </td>
                <td align="right">
                    <input type="button" class="button" value=" 清除 " onclick="ClearLog()" />
                    <input type="button" class="button" value="关闭" onclick="$('#ClearLogDialog').hide();$('#DIVMask').hide();" />
                </td>
            </tr>
        </tbody>
    </table>
    <div style="width: 488px; height: 100px; padding: 5px; border: #ccc 1px solid;">
        删除日期：<input type="text" style="width: 110px;" class="easyui-datebox delDate" onclick="SelectDate('sel_ClearlogTime')" />
        <input id="sel_ClearlogTime" type="hidden" />之前的记录.
    </div>
</div>
<div id="DIVMask">
</div>
